package com;

import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.RPCHook;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @description:
 * @author: sksun2
 * @create: 2023-02-13
 */
public class RocketMqStarter {

    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer(null,"skywalking",getAclRPCHook());
        producer.setNamesrvAddr("172.29.67.5:9876");
        producer.start();
        System.out.println("启动成功");


        producer.send(new Message(
                        "skywalking-meters",
                        "hello".getBytes()));
//        message.setTopic();
//        producer.send();
    }

    static RPCHook getAclRPCHook() {
//        SessionCredentials sc = new SessionCredentials(RocketmqReporterPluginConfig.Plugin.Rocketmq.APP_ID, RocketmqReporterPluginConfig.Plugin.Rocketmq.APP_SECRET);
        SessionCredentials sc = new SessionCredentials("0c4f2ae66e504199a5053872cca7f88b", "D615DBC94E23BA23E8F7E6658C870ADF");
        return new AclClientRPCHook(sc);
    }
}
